<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
class indexController extends Controller
{
    //index
    public function index()
    {
    	//顶部导航栏查询
    	$data = DB::table('sort') -> where('pid',0) ->where('id','>',1) -> get();

		$phones = DB::table('sort') -> where('pid',1) -> get();
        //轮播图
        $img = DB::table('imgs') -> get();
        // dd($img);
        //左侧导航栏查询
		// 手机
    	$phoneleft = DB::table('sort as s1')
    		-> select('s1.*','s1.name as sname','s2.name as name2','g.*')
    		-> leftjoin('sort as s2','s2.pid','=','s1.id')
    		-> leftjoin('goods as g','s2.id','=','g.sid')
    		-> where('s1.id','=','1')
    		-> get();
        foreach($phoneleft as $k => $value)
        {
            $phoneleft[$k] -> content = strip_tags($value -> content);
        }

        
    	//智能配件
    	$hards = DB::table('goods as g')
    		-> select('g.*','s.id','g.id as gid')
    		-> leftjoin('sort as s','s.id','=','g.sid')
    		-> where('s.name','=','智能配件')
    		-> get();
            //dd($hards);
        foreach($hards as $k => $value)
        {
            $hards[$k] -> content = strip_tags($value -> content);
        }
    	//精选配件
        $sort1 = DB::table('sort as s')
            -> select('s.id as sid','s.pid','g.*')
            -> leftjoin('goods as g','g.sid','=','s.id')
            -> where('s.name','耳机/音箱')
            -> get();
        $sort2 = DB::table('sort as s')
            -> select('s.id as sid','s.pid','g.*')
            -> leftjoin('goods as g','g.sid','=','s.id')
            -> where('s.name','路由器/移动电源')
            -> get();
        $sort4 = DB::table('sort as s')
            -> select('s.id as sid','s.pid','g.*')
            -> leftjoin('goods as g','g.sid','=','s.id')
            -> where('s.name','保护套/后盖/贴膜')
            -> get();
        $sort6 = DB::table('sort as s')
            -> select('s.id as sid','s.pid','g.*')
            -> leftjoin('goods as g','g.sid','=','s.id')
            -> where('s.name','数据线/电源适配器')
            -> get();
        $sort7 = DB::table('sort as s')
            -> select('s.id as sid','s.pid','g.*')
            -> leftjoin('goods as g','g.sid','=','s.id')
            -> where('s.name','周边配件')
            -> get();
            // dd($sort1);
        $hands = DB::table('sort as s1')
            -> select('s2.*','g.id as gid','g.img as gimg','g.content','g.name as gname','g.price')
            -> leftjoin('sort as s2','s2.pid','=','s1.id')
            -> leftjoin('goods as g','g.sid','=','s2.id')
            -> where('s1.name','精选配件')
            -> get();
        foreach($hands as $k => $value)
        {
            $hands[$k] -> content = strip_tags($value -> content);
        }
        //手机周边
        $condoms = DB::table('sort as s')
            -> select('s.id','g.id as gid','g.img as gimg','g.content','g.name as gname','g.price')
            -> leftjoin('goods as g','g.sid','=','s.id')
            -> where('s.name','保护套/后盖/贴膜')
            -> get();
            foreach($condoms as $k => $value)
        {
            $condoms[$k] -> content = strip_tags($value -> content);
        }
        // 热门推荐
        $max = DB::table('goods') -> where('hot','1') -> get();
        // dd($max);
    	return view('home.index',['data' => $data, 'phones' => $phones, 'phoneleft' => $phoneleft, 'hards' => $hards, 'hands' => $hands,'condoms' => $condoms,'max' => $max,'img' => $img,'sort1' => $sort1,'sort2' => $sort2,'sort4' => $sort4,'sort6' => $sort6,'sort7' => $sort7]);
    }
}
